package com.tanhua.server.controller;

import com.tanhua.model.mongo.Movement;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.VisitorsVo;
import com.tanhua.server.service.CommentsService;
import com.tanhua.server.service.MovementsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author 刘付磊
 * @date 2021/11/17 0017
 */
@RequestMapping("/movements")
@RestController
public class MovementController {
    //发布动态
    @Autowired
    private MovementsService movementsService;

    @Autowired
    private CommentsService commentsService;

    @PostMapping
    public ResponseEntity movements(Movement movement, MultipartFile imageContent[]) throws IOException {
        movementsService.movements(movement,imageContent);
        return ResponseEntity.ok(null);
    }
    /*查询我的动态*/
    @GetMapping("/all")
    public ResponseEntity findAll(Long userId,
                                  @RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = movementsService.findAll(userId,page,pagesize);
        return ResponseEntity.ok(pr);
    }
    /*查询好友动态*/
    @GetMapping
    public ResponseEntity findFriendMovements(@RequestParam(defaultValue = "1") Integer page,
                                              @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = movementsService.findFriendMovements(page,pagesize);
        return ResponseEntity.ok(pr);
    }
    /*查询推荐动态*/
    @GetMapping("/recommend")
    public ResponseEntity recommend(@RequestParam(defaultValue = "1") Integer page,
                                              @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = movementsService.recommend(page,pagesize);
        return ResponseEntity.ok(pr);
    }
    /*查询单条动态*/
    @GetMapping("/{id}")
    public ResponseEntity findById(@PathVariable("id") String movementId){
       MovementsVo vo = movementsService.findById(movementId);
       return ResponseEntity.ok(vo);
    }
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String movementId){
        Integer likeCount = commentsService.likeCovement(movementId);
        return ResponseEntity.ok(likeCount);
    }
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String movementId){
        Integer likeCount =commentsService.dislikeCovement(movementId);
        return ResponseEntity.ok(likeCount);
    }
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") String movementId){
        Integer likeCount = commentsService.loveCovement(movementId);
        return ResponseEntity.ok(likeCount);
    }
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") String movementId){
        Integer likeCount =commentsService.unloveCovement(movementId);
        return ResponseEntity.ok(likeCount);
    }
    /**
     * 谁看过我
     */
    @GetMapping("visitors")
    public ResponseEntity queryVisitorsList(){
        List<VisitorsVo> list = movementsService.queryVisitorsList();
        return ResponseEntity.ok(list);
    }
   /* @GetMapping("/{id}/{like}")
    public ResponseEntity like(@PathVariable("id") String movementId, HttpServletRequest request){
        Integer CovementLikeAndLove = commentsService.CovementLikeAndLove(movementId);
        return ResponseEntity.ok(CovementLikeAndLove);
    }*/

}
